export default {
  //随机生成len位验证码
  GetCode(len){
    let str = `qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890`
    let newstr = ''
    for(let i = 0 ;i < len; i++){
      newstr += str.charAt(getRandom(0,str.length-1))
    }
    return newstr
  },
  //随机生成颜色
  GetRandomColor(){
    var c1 = getRandom(0, 255);
    var c2 = getRandom(0, 255);
    var c3 = getRandom(0, 255);
    return 'rgb(' + c1 + ',' + c2 + ',' + c3 + ')'
  },
  //生成星座
  GetConstellation(timer){
    let constellation = ''
    timer = parseInt(timer)
    console.log(timer);
    let constellations = [
      {name: '白羊座', t: [321,419]},{name: '金牛座', t: [420,520]},{name: '双子座', t: [521,621]},
      {name: '巨蟹座', t: [622,722]},{name: '狮子座', t: [723,822]},{name: '处女座', t: [823,922]},
      {name: '天秤座', t: [923,1023]},{name: '天蝎座', t: [1024,1122]},{name: '射手座', t: [1123,1221]},
      {name: '魔蝎座', t: [1222,119]},{name: '水瓶座', t: [120,218]},{name: '双鱼座', t: [219,320]},
    ]
    for(let item in constellations){
      if(timer>=constellations[item].t[0] && timer<=constellations[item].t[1]){
        constellation = constellations[item].name
        break;
      }else if((timer>=1222 && timer<=1231) || (timer>=101 && timer<=119)){
        constellation = '魔蝎座'
        break;
      }
    }
    return constellation
  },
  // 时间转换
  GetTimer(time){
    time = time || ''
    let ms =  new Date().getTime()-new Date(time).getTime()
    let min = ms/1000/60
    let hour = min/60
    let day = hour/24
    let mon = day/30
    if(min<1){
      time = '刚刚'
    }else if(min >= 1 && min < 60){
      time = parseInt(min) + '分钟前'
    }else if(hour >= 1 && hour < 24){
      time = parseInt(hour) + '小时前'
    }else if(day >= 1 && day < 31){
      time = parseInt(day) + '天前'
    }else if(mon >=1 && mon < 12){
      time = parseInt(mon) + '月前'
    }else{
      time = time.split('T').join(' ')
    }
    return time
  },
  // 俩字符串相似度
  GetCompare(a,b){
    let Len = a.length + b.length
    let sum = 0
    for(let i=0; i<b.length; i++){
      if(a.indexOf(b[i]) != -1)
        sum++
    }
    for(let i=0; i<a.length; i++){
      if(b.indexOf(a[i]) != -1)
        sum++
    }
    return Math.floor(sum/Len*100)
  }
}

// 需要随机生成 min-max 之间的整数
function getRandom(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}